<template>
    <div>
        <button @click="convert">json导出为csv</button>
    </div>
</template>

<script>
    import {convertToCSV} from '../util/csvTool'
    import {downloadFile} from "../util/downLoad"

    export default {
        name: "JsonToCsvView",
        data() {
            return {
                jsonData: [
                    { name: 'John', age: 30, city: 'New York' },
                    { name: 'Jane', age: 25, city: 'Los Angeles' },
                    { name: 'Bob', age: 35, city: 'Chicago' }
                ],
                csvData: ''
            };
        },
        methods: {
            convert() {
                const csv = convertToCSV(this.jsonData);
                this.csvData = csv;
                // 如果你想将 CSV 数据保存到文件，可以使用以下方法：
                downloadFile(csv, 'data.csv');
            }
        }
    }
</script>

<style scoped>

</style>